<template>
	<view>
		<template v-if="hasDataFlag">
			<view class="gridList"
				:class="[currIndex == index ? 'active' : '']"
				v-for="(item,index) in vilageList"
				:key="index"
				@tap="goSelCurrVillage(index,item)"
			>{{item.villageName}}</view>
		</template>
		<template v-else-if="hasDataFlag == false">
			<no-data noDataTxt="暂无网格"></no-data>
		</template>
	</view>
</template>

<script>
	import { getSqGroupData } from '@/api/mine/index'
	export default {
		data(){
			return{
				//fromPage:'',//selCpArea->测评个人信息 applyRz(咨询师申请入住)
				countyName:'',
				townName:'',
				groupId:0,
				currIndex:-1,
				vilageList:[],
				hasDataFlag:null
			}
		},
		onLoad(option){
			this.countyName = option.countyName;
			this.townName = option.townName;
			this.groupId = option.groupId;
			this.loadGridList();
		},
		methods:{
			loadGridList(){
				let field = { county:this.countyName,town:this.townName }
				getSqGroupData(field).then(res=>{
					//console.log(res)
					this.vilageList = res.data.datas;
					this.hasDataFlag = true;
					if(this.groupId > 0){
						for(let i in this.vilageList){
							if(this.vilageList[i].groupId == this.groupId){
								this.currIndex = Number(i);
							}
						}
					}
				}).catch(err=>{
					this.hasDataFlag = false;
					console.log(err)
				})
			},
			goSelCurrVillage(index,item){
				this.currIndex = index;
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.$vm.gridName = item.villageName;
				prevPage.$vm.groupId = item.groupId;
				prevPage.$vm.selGridFlag = true;
				uni.navigateBack({delta:1})
			}
		}
	}
</script>

<style lang="scss">
	page{
		border-top: $comBor;
		background: $pss-bg-primary;
	}
	@import '@/static/scss/gridList.scss';
</style>